home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 9 / Night Owl CD-ROM (NOPV9) (Night Owl Publisher) (1993).ISO / 009a / snpd0493.zip / MKDIRS.C < prev    next >
C/C++ Source or Header  |  1993-04-05  |  1KB  |  53 lines

  1. /*
  2. **  MKDIRS.C - Function to build multi-level directories in a single call
  3. **
  4. **  Original Copyright 1993 by Bob Stout as part of
  5. **  the MicroFirm Function Library (MFL)
  6. **
  7. **  This subset version is hereby donated to the public domain.
  8. */
  9.  
  10. #include <stdio.h>
  11. #include <stdlib.h>
  12. #include <string.h>
  13. #ifdef __TURBOC__
  14.  #include <dir.h>
  15. #else
  16.  #include <direct.h>
  17. #endif
  18.  
  19. int mkdirs(char *path)
  20. {
  21.       int retval;
  22.  
  23.       while (0 != (retval = mkdir(path)))
  24.       {
  25.             char subpath[FILENAME_MAX] = "", *delim;
  26.  
  27.             if (NULL == (delim = strrchr(path, '\\')))
  28.                   return retval;
  29.             strncat(subpath, path, delim - path);     /* Appends NUL    */
  30.             mkdirs(subpath);
  31.       }
  32.       return retval;
  33. }
  34.  
  35. #ifdef TEST
  36.  
  37. main(int argc, char *argv[])
  38. {
  39.       if (2 > argc)
  40.       {
  41.             puts("Usage: MKDIRS pathname [...pathname]");
  42.             return -1;
  43.       }
  44.       while (--argc)
  45.       {
  46.             ++argv;
  47.             printf("mkdirs(%s) returned %d\n", *argv, mkdirs(*argv));
  48.       }
  49.       return 0;
  50. }
  51.  
  52. #endif /* TEST */
  53.